# -*- encoding:utf-8 -*-
from pymongo import MongoClient,ASCENDING
import datetime
#
#client = MongoClient()
client = MongoClient('localhost',27017)
#client = MongoClient("mongodb://localhost:27017/")

#get db
db = client.mjoin
#get collection
#print db.collection_names()  #查询db下的collections	


#insert data
#db.users.insert({'name':'smark','age':12})  
#insert mmeny users
# db.u
#sers.drop()   #db.users.remove({})


# for i in range(1000):                  #批量初始化user
# 	db.users.insert({'name':'user'+str(i),'age':1000-i})
#db.users.update({'name':'user0'},{'$set':{'name':'userupated'}})  #修改数据

# db.users.insert({'name':'smark','computers':['fedora','ubuntu','win8.1']})
# print db.users.find_one({'computers.0':'fedora'})                #配置指定位置上的数组值
# print db.users.find_one({'computers.0':'fedora'},{'name':0})     #限制返回列
# print db.users.find_one({'computers':'fedora'},{'name':1})        #返回指定列


# for row in db.users.find({'age':{'$lt':5}}).sort('name',-1):
# 	print row

# print "count :"+str(db.users.count())
#db.accounts.save({'name':"a",'blance':1000,'pendingTransactions':[]})
#db.accounts.save({'name':"b",'blance':1000,'pendingTransactions':[]})
for row in db.users.find():
	print row